#ifndef tlmRmtCfgSrvApp_H
#define tlmRmtCfgSrvApp_H

//## attribute mParaAdmin
#include "tlmRmtCfgParaAdmin.h"
//## attribute mParaNavi
#include "tlmRmtCfgParaNavi.h"
//## attribute mParaWeb
#include "tlmRmtCfgParaWeb.h"
//## class tlmRmtCfgSrvApp
#include "tlmServiceApp.h"
#include "ActiveClass.h"

//## operation OnReceiveMsg(tlmServiceMsg)
class tlmServiceMsg;


//## class tlmRmtCfgSrvApp
class tlmRmtCfgSrvApp : public tlmServiceApp, public ActiveClass{
    ////    Friends    ////
public:
    #define TLM_ACK_STATUS_OK 0
    #define TLM_ACK_STATUS_KO 1
    #define TLM_ACK_STATUS_OUTSIDE_LIMITS 2   

    #define TLM_RMT_CFG_TIMEOUT 1500 // Each tick is 20 ms - 120 sec timer
    
public :


    ////    Constructors and destructors    ////
    
    tlmRmtCfgSrvApp();
    
    virtual ~tlmRmtCfgSrvApp();
	
	void initialize();
    
    ////    Operations    ////
    
    //## operation GetAckStatus()
    uint8_t GetAckStatus();
    
    //## operation GetInstance()
    static tlmRmtCfgSrvApp* GetInstance();

    void destroyInstance();
    
    //## operation GetParaAdmin()
    virtual tlmRmtCfgParaAdmin* GetParaAdmin();
    
    //## operation GetParaNavi()
    virtual tlmRmtCfgParaNavi* GetParaNavi();
    
    //## operation GetParaWeb()
    virtual tlmRmtCfgParaWeb* GetParaWeb();
    
    //## operation OnReceiveMsg(tlmServiceMsg)
    virtual void OnReceiveMsg(tlmServiceMsg* srvMsg);
    
    //## operation SaveParameters()
    uint8_t SaveParameters();
    
    //## operation SendMsg(tlmServiceMsg) const
    void SendMsg(tlmServiceMsg* msg) ;
    
    //## operation __OnReceiveMsg(tlmServiceMsg)
    void __OnReceiveMsg(tlmServiceMsg* srvMsg);
    
    //## operation __OnReceivePendingMsg(tlmServiceMsg) const
    void __OnReceivePendingMsg(tlmServiceMsg* srvMsg) ;
    
    //## operation __OnReceiveReqParaMsg(tlmServiceMsg)
    void __OnReceiveReqParaMsg(tlmServiceMsg* srvMsg);
    
    //## operation __OnReceiveSetParaMsg(tlmServiceMsg)
    void __OnReceiveSetParaMsg(tlmServiceMsg* srvMsg);
	
    void SendHttpMsg(uint8_t* msgPayload, uint32_t length); 

    void tlmRmtCfgSrvApp_makeAsyncCall(DWORD funcId,DWORD* pData,DWORD size);

    void CheckNewPendMsg(tlmServiceMsg* srvMsg); 
    void CheckNewGetCfgMsg(tlmServiceMsg* srvMsg);
    void onReceiveNewPendMsg(tlmServiceMsg* srvMsg);
    void onReceiveNewGetCfgMsg(tlmServiceMsg* srvMsg);
    void HandlePendingMsg(tlmServiceMsg* srvMsg); 
    void HandleGetCfgMsg(tlmServiceMsg* srvMsg);
    void SendConMsg(void);
    void SendParaMsg(void);
    void OnReqConnection(void); 
    void RequestConnection(void) ;

    void OnReceiveHttpMsg(uint8_t* msgPayload, uint32_t length);
    void __OnReceiveHttpMsg(tlmServiceMsg* srvMsg);
    void HandleSetConfigMsg(tlmServiceMsg* srvMsg) ;
    void SendAckMsg(void);
    void OnGetCfgTimeOut(void);
    void OnSetCfgTimeOut(void);
protected :
     /// operation __SyncCall(RPC_IOCTL_PTR)
     virtual void __SyncCall(RPC_IOCTL_PTR p);
 
     /// operation __AsyncCall(RPC_IOCTL_PTR)
     virtual void __AsyncCall(RPC_IOCTL_PTR p);    
	 
protected :

    uint8_t mAckStatus;		//## attribute mAckStatus
    
    tlmRmtCfgParaAdmin mParaAdmin;		//## attribute mParaAdmin
    
    tlmRmtCfgParaNavi mParaNavi;		//## attribute mParaNavi
    
    tlmRmtCfgParaWeb mParaWeb;		//## attribute mParaWeb

    tlmServiceMsg * mCurPendingMsg;
    tlmServiceMsg * mCurGetCfgMsg;
    
    static tlmRmtCfgSrvApp* mpInstance;		//## attribute mpInstance

    uint8_t mSetSessionId;
    uint8_t mGetSessionId;
};
#endif
